#include "atime.h"

ATime::ATime()
{}

ATime::ATime(int hs, int ms, int ss): hours(hs), mins(ms), secs(ss)
{}

ATime::ATime(const QTime &t): hours(t.hour()), mins(t.minute()), secs(t.minute())
{}

ATime ATime::fromSeconds(int ss)
{
	int s = ss;
	
	int m = s / 60;
	s %= 60;
	
	int h = m / 60;
	m %= 60;
	
	return ATime(h, m, s);
}

ATime ATime::fromMinutes(int ms)
{
	int s = 0;
	int m = ms;
	
	int h = m / 60;
	m %= 60;
	
	return ATime(h, m, s);
}

ATime ATime::fromHours(int hs)
{
	int s = 0;
	int m = 0;
	int h = hs;
	
	return ATime(h, m, s);
}

QString ATime::toString(const QString &format) const
{
	return format.arg(hours, 2, 10, QChar('0')).arg(mins, 2, 10, QChar('0')).arg(secs, 2, 10, QChar('0'));
}

ATime operator+(const ATime &l, const ATime &r)
{
	ATime t;
	t.fromSecs(l.toSecs() + r.toSecs());
	
	return t;
}

ATime operator-(const ATime &l, const ATime &r)
{
	ATime t;
	t.fromSecs(l.toSecs() - r.toSecs());
	
	return t;
}
